package com.xsm.activitygroup;

import java.util.ArrayList;

import com.xsm.DataBase.SaveMessage;
import com.xsm.activitygroup.R;
import com.xsm.adapter.MyAdapter;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;

public class TypeC extends Activity{
	Myhandler hanMyhandler;
	Context context;
	ArrayList<String> arrayList=new ArrayList<String>();
	ListView typeclist;
	MyAdapter adapter;
	TextView textView;
protected void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_NO_TITLE);
	super.onCreate(savedInstanceState);
	setContentView(R.layout.tuijian);
	context=this;
	typeclist=(ListView)findViewById(R.id.tuijianlist);
	textView=(TextView)findViewById(R.id.title);
	textView.setText("分类");
	adapter=new MyAdapter(context,null, arrayList);
	typeclist.setAdapter(adapter);
	typeclist.setOnItemClickListener(new OnItemClickListener() {
		public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
				long arg3) {
			String type=arrayList.get(arg2);
			Intent intent=new Intent();
			intent.putExtra("typec", type);
			intent.setClass(context, Tuijian.class);
			startActivity(intent);
		}
	});
	final int parentid =getIntent().getExtras().getInt("parentid");
	hanMyhandler=new Myhandler();
	new Thread(new Runnable() {
		public void run() {
ArrayList<String>  array=new SaveMessage(context).getTypec(parentid);	
for(int i=0;i<array.size();i++){
	arrayList.add(array.get(i));
}
Message msg=hanMyhandler.obtainMessage();
msg.what=1;
hanMyhandler.sendMessage(msg);
		}
	}).start();
}

public void Back(View view){
	finish();
}
class Myhandler extends Handler{
	public void handleMessage(Message msg) {
		if(msg.what==1){
		adapter.notifyDataSetChanged();	
		}
		super.handleMessage(msg);
	}
}

}
